package com.douqu.game;

import com.douqu.game.test.Person;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Test {

    public static void main(String[] args)
    {
        Test test = new Test();
        test.add(1, "张三");

        System.out.println("list -> " + test.getList());

        test.remove(1);

        System.out.println("list => " + test.getList());
    }


    private List<Person> list = new CopyOnWriteArrayList<>();

    public void add(int id, String name)
    {
        list.add(new Person(id, name));
    }

    public void remove(int id)
    {
        for(Person person : list)
        {
            if(person.getId() == id)
            {
                list.remove(person);
                break;
            }
        }
    }

    public List<Person> getList() {
        return list;
    }

    public void setList(List<Person> list) {
        this.list = list;
    }
}